home *** CD-ROM | disk | FTP | other *** search
- Path: Austria.EU.net!usenet
- From: niederle@deas.co.at
- Newsgroups: comp.lang.c++
- Subject: Templates and Recursive Structures
- Date: 29 Jan 1996 11:49:49 GMT
- Organization: DEAS EDV-Loesungen GmbH, 1070 Wien
- Message-ID: <4eic8t$20g@news.Austria.EU.net>
- NNTP-Posting-Host: s16.vie2.austria.eu.net
- X-Newsreader: AIR News 3.X (SPRY, Inc.)
-
- I want to define an array type of my own and use it to build tree-like
- structures:
-
- struct T2;
-
- struct T1
- {
- ARRAY <T2>
- };
-
- struct T2
- {
- ARRAY <T1>
- };
-
- The data structure defined would be absolutely sensefull because the leafes
- of the tree will contain empty arrays.
-
- The problem is that within the ARRAY class I need the size of the base type
- to access the array's items.
-
- e.g. try the following simple ARRAY class
- (the size is used implicitely in "buf[idx]"):
-
- template <class BASE_TYPE>
- struct ARRAY
- {
- BASE_TYPE *buf;
-
- BASE_TYPE &operator [](int idx)
- {
- return buf[idx];
- }
- }
-
- The compiler reports an error when creating the template member function
- operator [] for T1 because it does no know the size of T2 at this moment!
-
- Is there a solution or is this a general leak in the specification of C++?
-
- I tried the above examples with BORLAND C++ 4.5.
-
- mfG Michael Niederle
-
-